package com.guigu.serviceorder.controller;

import com.guigu.serviceorder.entity.TbOrder;
import com.guigu.serviceorder.service.ITbOrderService;
import com.guigu.serviceorder.service.WeixinPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("wxpay")
public class WxPayController {

    @Autowired
    private ITbOrderService orderService;

    @Autowired
    private WeixinPayService wxPayService;

    @GetMapping("/createNative")
    public Map createNative(String orderId,String username,String notifyUrl){
        TbOrder order = orderService.getById(orderId);
        if(order!=null){
            if("0".equals(order.getPayStatus()) && "0".equals(order.getOrderStatus()) && username.equals(order.getUsername()) ){
                return wxPayService.createNative(orderId,order.getPayMoney(),notifyUrl);
            }else{
                return null;
            }
        }else{
            return null;
        }
    }

    @GetMapping("notify")
    public void notifyLogic(String xml){
        wxPayService.notifyLogic(xml);
    }


}
